//
//  ViewController.m
//  XiangMu
//
//  Created by 康世标 on 15/7/16.
//  Copyright (c) 2015年 康世标. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [super viewDidLoad];
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"yindaoye"]==NULL)
    {
        YinDaoViewController * yi = [[YinDaoViewController alloc]init];
        
        AppDelegate * app =(AppDelegate *)[UIApplication sharedApplication].delegate;
        app.window.rootViewController = yi;

        
    }
    else{
        
        [self tabbColtion];
        
    }
//   NSLog(@"----%@",NSHomeDirectory());
}
- (void)tabbColtion{
    
    UITabBarController * tabcotroller = [[UITabBarController alloc]init];
    //    首页
    ShouYeViewController * shouYe = [[ShouYeViewController alloc]init];
    
    UINavigationController * nav = [[UINavigationController  alloc]initWithRootViewController:shouYe];
    
    nav.tabBarItem.image = [[UIImage imageNamed:@"Image11"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    nav.tabBarItem.selectedImage = [[UIImage imageNamed:@"Image12"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    shouYe.title = @"爱+护理";
    
    nav.tabBarItem.title = @"首页";
    //    nav.tabBarItem.selectedImage=[]
    
    //陪护师
    PeiHuShiViewController*peiHuShi = [[PeiHuShiViewController alloc]init];
    UINavigationController*nav1 = [[UINavigationController  alloc]initWithRootViewController:peiHuShi];
    nav1.tabBarItem.image = [[UIImage imageNamed:@"Image21"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    nav1.tabBarItem.selectedImage = [[UIImage imageNamed:@"Image22"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    peiHuShi.title = @"陪护师";
    
    
    //    我的
    WoDeViewController * woDe = [[WoDeViewController alloc]init];
    UINavigationController * nav2 = [[UINavigationController  alloc]initWithRootViewController:woDe];
    woDe.title=@"我的";
    
    nav2.tabBarItem.image = [[UIImage imageNamed:@"Image31"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    nav2.tabBarItem.selectedImage = [[UIImage imageNamed:@"Image32"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabcotroller.viewControllers = @[nav,nav1,nav2];
    
    tabcotroller.delegate = self;
    
    [self.view addSubview:tabcotroller.view];
    
    [self addChildViewController:tabcotroller];
    
    if (![UserManager login])
    {
        
        [UserManager GuoQiLeMa];
    }
    



}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    NSString * msg = [[NSUserDefaults standardUserDefaults]objectForKey:@"msg"];
  
    if ([msg isEqualToString:@""]||msg ==nil)
    {
        
        if ([viewController.title isEqualToString:@"我的"])
        {
            
            UIAlertView * alertView =[[UIAlertView alloc]initWithTitle:@"请先登录" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
            [alertView show];
            return NO;
        }
        return YES;
        
        
    }
    else{
        
        return YES;
    }
    
}
#pragma mark---UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex==0) {
        
        DengLuViewController * de =[[DengLuViewController alloc]init];
        
        UINavigationController * nav= [[UINavigationController alloc]initWithRootViewController:de];
        
        [self presentViewController:nav animated:YES completion:nil];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
